#!/usr/bin/env python
#coding:utf-8

import os
import sys
import wx

class MainWindow(wx.Frame):
    """ We simply derive a new class of Frame. """
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(500,100))
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar()
        self.createMenuBar() #创建菜单

    def menuData(self):
        '''创建菜单项'''
        return (("&File",
                 ("&New", "new file", self.OnNew),
                 ("&Open", "Open in status bar", self.OnOpen),
                 ("&Quit", "Quit", self.OnCloseWindow)),
                ("&Edit",
                 ("&Copy", "Copy", self.OnCopy),
                 ("C&ut", "Cut", self.OnCut),
                 ("&Paste", "Paste", self.OnPaste),
                 ("", "", ""),
                 ("&Options", "DisplayOptions", self.OnOptions)),
                ("&Help",
                 ("Help", "hele for this software", self.OnHelp),
                 ("About", "about for this software", self.OnAbout))
                )
    def createMenuBar(self):
        menuBar = wx.MenuBar()
        for eachMenuData in self.menuData():
            menuLabel = eachMenuData[0]
            menuItems = eachMenuData[1:]
            menuBar.Append(self.ceateMenu(menuItems), menuLabel)
        self.SetMenuBar(menuBar)

    def createMenu(self):
        menu = wx.Menu()
        for eachLabel, eachStatus, eachHandler in menuData:
            if not eachLabel:
                menu.AppendSeparator()
                continue
            menuItem = menu.Append(-1, eachLabel, eachStatus)
            self.Bind(wx.EVT_MENU, eachHandler, menuItem)
        return menu

    
